package com.huike.web.controller.review;


import com.github.pagehelper.PageInfo;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.review.service.ReviewService;
import com.huike.review.vo.MybatisReviewVO;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.ServiceMode;
import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    /**=========================================================新增数据============================================*/

    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData(@PathVariable String name,
                               @PathVariable Integer age,
                               @PathVariable String sex){
reviewService.saveData(name,age,sex);
return AjaxResult.success("成功插入一条数据");

    }

    @PostMapping("/saveData")
    public AjaxResult saveData1(MybatisReviewVO mybatisReviewVO){
        reviewService.saveData1(mybatisReviewVO);
        return AjaxResult.success("成功插入一条数据");
    }
    /**=========================================================删除数据=============================================*/
    @DeleteMapping("/remove/{id}")
    public AjaxResult delete(@PathVariable Long id){
        reviewService.delete(id);
        return AjaxResult.success("成功删除一条数据");
    }
    /**=========================================================修改数据=============================================*/

    @PostMapping("/update")
    public AjaxResult update( MybatisReviewVO mybatisReviewVO){
        reviewService.update(mybatisReviewVO);
        return AjaxResult.success("修改成功");
    }
    /**=========================================================查询数据=============================================*/
//通过id来查询
    @GetMapping("/getById")
    public AjaxResult  getById(Long id){
        MybatisReviewVO m =reviewService.getById(id);
        return AjaxResult.success(m);
    }
//分页查询
    @GetMapping("/getDataByPage")
    public PageInfo<MybatisReviewVO> getDataByPage(@RequestParam(defaultValue = "18")Integer pageNum,
                                                   @RequestParam(defaultValue = "10")Integer pageSize){
        PageInfo<MybatisReviewVO> page = reviewService.getDateByPage(pageNum, pageSize);
        return page;

    }
}